import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';
const baseUrl = '/sales/api/v1';

const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询'
});
const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询详情'
});
const updateDesc = formatMessage({
    id: 'api.message.updateDesc',
    defaultMessage: '修改'
});
const abandonDesc = formatMessage({
    id: 'api.message.abandonDesc',
    defaultMessage: '作废'
});
const exportDesc = formatMessage({
    id: 'api.message.queryExport',
    defaultMessage: '导出'
});
const brandDesc = formatMessage({
    id: 'api.message.brandDesc',
    defaultMessage: '查询品牌'
});
const getMarketDepartmentDesc = formatMessage({
    id: 'api.message.getMarketDepartmentDesc',
    defaultMessage: '查询大区'
});
// 查询列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/kdProductionPlans?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询详情
export const getDetail = id =>
    request(`${baseUrl}/kdProductionPlans/${id}`, null, dto.Detail)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));
//修改
export const updateApplyReport = (id, data) => request(`${baseUrl}/kdProductionPlans/${id}`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, updateDesc));
//作废
export const abandonData = (id, data) => request(`${baseUrl}/kdProductionPlans/${id}/abandon`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, abandonDesc));
//导出
export const queryExport = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/kdProductionPlans/export?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDesc))
        .then(res => res.data);
};
//导入模板
export const importTemp = () => request(`${baseUrl}/kdProductionPlans/importTemp`)
    .then(handleFetchResultNotification(REQUEST_TYPE.query, null)).then(res => res.data);
import {baseDataStatus} from '../Enum';
// 获取品牌
export const getBrands = () => {
    const queryCondition = stringify({
        status: baseDataStatus.生效
    });
    return request(`${baseUrl}/brands?${queryCondition}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, brandDesc));
};
// 查询大区
export const getMarketDepartment = condition => {
    const queryString = stringify(condition);
    return request(`${baseUrl}/marketDepartments?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getMarketDepartmentDesc));
};
// 查询大区
export const getMarketDepartmentSimple = condition => {
    const queryString = stringify(condition);
    return request(`${baseUrl}/marketDepartments/simple?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getMarketDepartmentDesc));
};
